package br.com.socialmeeting.services;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.com.socialmeeting.dao.impl.PerfilDaoImp;
import br.com.socialmeeting.dao.impl.UsuarioDaoImp;
import br.com.socialmeeting.model.Usuario;

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@Service("hibernateUserDetailsService")
public class HibernateUserDetailsService extends HibernateDaoSupport implements UserDetailsService  {
	
	@Autowired
	private UsuarioDaoImp usuarioDaoImp;
	
	@Autowired
	private PerfilDaoImp perfilDaoImp;
	
	@Autowired
	public HibernateUserDetailsService(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}

	public UserDetails loadUserByUsername(String login) {
		
		Usuario resultado = usuarioDaoImp.findByName(login);
		
		return resultado;
	}
	
	
}
